package com.yan_jiu_sheng.LeetCodeHot100.AC;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/rotate-image/description/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 *
 * @author yulongTian
 * @create 2024-05-29 10:55
 */
public class Test20 {
    public static void main(String[] args) {
//        int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        int[][] matrix = {{5, 1, 9, 11}, {2, 4, 8, 10}, {13, 3, 6, 7}, {15, 14, 12, 16}};
        new Test20().rotate(matrix);
        System.out.println(Arrays.deepToString(matrix));
    }

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        int quan = (n + 1) / 2;
        for (int k = 0; k < quan; k++) {
            for (int p = 0; p < n - 1; p++) {
                int temp = matrix[k][k + p];
                matrix[k][k + p] = matrix[k + n - 1 - p][k];
                matrix[k + n - 1 - p][k] = matrix[k + n - 1][k + n - 1 - p];
                matrix[k + n - 1][k + n - 1 - p] = matrix[k + p][k + n - 1];
                matrix[k + p][k + n - 1] = temp;
            }
            n -= 2;
        }
    }

}
